package com.homedo.odin.solution.service;

import com.homedo.core.common.base.service.BaseService;
import com.homedo.odin.solution.dao.UserScoreDetailMapper;
import com.homedo.odin.solution.model.entity.UserScoreDetail;
import org.springframework.stereotype.Service;

/**
 * <p> 用户积分明细 服务实现类 </p>
 *
 * @author HarveyDing
 * @since 2018-03-08
 */
@Service
public class UserScoreDetailServiceImpl extends BaseService<UserScoreDetailMapper, UserScoreDetail> {

    public UserScoreDetail selectBySignInAndDate(Integer userId, String date, Integer type) {
        return baseMapper.selectBySignInAndDate(userId, date, type);
    }

    public Integer selectCountByTypeAndUserId(Integer userId, Integer type) {
        return baseMapper.selectCountByTypeAndUserId(userId, type);
    }

    public void insert(Integer userId, Integer type, Integer score, String bizCode) {
        UserScoreDetail detail = new UserScoreDetail();
        detail.setCreatedBy(userId);
        detail.setModifiedBy(userId);
        detail.setScore(score);
        detail.setUserId(userId);
        detail.setBizCode(bizCode);
        detail.setType(type);
        baseMapper.insert(detail);
    }

    /**
     * 查找当天签到数据
     */
    public UserScoreDetail findByTodaySingIn(Integer type, Integer userId) {
        return baseMapper.findByTodaySingIn(type, userId);
    }

    public UserScoreDetail findByUserIdAndBizCodeAndType(Integer userId, String bizCode, Integer type) {
        UserScoreDetail detail = new UserScoreDetail();
        detail.setBizCode(bizCode);
        detail.setType(type);
        detail.setUserId(userId);
        detail.setIsDel(0);
        return baseMapper.selectOne(detail);
    }
}
